
    //判断本地是否有token
    if (!localStorage.getItem('token')) {
        location.href = './login.html'
    }
    //获取个人数据,并渲染到页面
    function getuser() {
        axios.get('http://api-breakingnews-web.itheima.net/my/userinfo', {
            headers: {
                Authorization: localStorage.getItem('token')
            }
        }).then(function (test) {


            if (test.data.status === 0) {
                let { email, id, nickname, user_pic, username } = test.data.data

                username = nickname || username

                if (!user_pic) {
                    const firstLrtter = username[0].toUpperCase()
                    $('.avatar').css('display', 'inline-block').html(firstLrtter)
                } else {
                    $('.avatar').css('display', 'none')
                    $('.layui-nav-img').css('display', 'inline-block').prop(`src`, user_pic)
                }
                $('.username').html(username)
            } else {
                localStorage.removeItem('token')
                location.href = './login.html'
            }

        })
    }
    getuser()
    window._getuser = getuser

    $('#logout').on('click', () => {
        layer.confirm('亲,您是要退出么,要不在好好想想?', { icon: 1, title: '温馨提示' }, function (index) {
          localStorage.removeItem('token')    
          location.href = './login.html'
          layer.close(index);
        });
      })
